package com.song.html;

public class STable {
	public String table(String args,String... body){
		return "<table "+args+">"+strsToString(body)+"</table>";
	}
	public String tr(String args,String... body){
		return "<tr "+args+">"+strsToString(body)+"</tr>";
	}
	public String td(String args,String body){
		return "<td "+args+">"+body+"</td>";
	}
	public String th(String args,String body){
		return "<th "+args+">"+body+"</th>";
	}
	public String args(String... body){
		if(body.length%2==1)return "";
		String arg = "";
		for(int i=0;i<body.length;i+=2){
			arg += body[i] + "='" + body[i+1] +"'";
		}
		return arg;
	}
	public String strsToString(String[] bodys){
		String body = "";
		for(int i=0;i<bodys.length;i++){
			body += bodys[i];
		}
		return body;
	}	
	public void test(){
		String table1 = table(args("border","1"),
				tr("",th("","th1"),th("","th2")),
				tr("",td("","r1,c1"),td("","r1,c2")));
		System.out.println(table1);
	}
}
